<template>
  <div>
    <el-date-picker
      v-model="searchTime"
      type="daterange"
      align="right"
      size="small"
      range-separator="~"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      style="width:100%"
      @change="timeChange"
    />
  </div>
</template>

<script>
export default {
  props: {
    status: {
      type: Number,
      required: false,
      default: 0
    }
  },
  data() {
    return {
      searchTime: []
    }
  },
  methods: {
    clearDate() {
      this.searchTime = []
    },
    // 将日期传递给父组件
    timeChange(val) {
      if (val) {
        var startTime =
          new Date(val[0].toLocaleDateString() + ' 00:00:00').getTime() / 1000
        var endTime =
          new Date(val[1].toLocaleDateString() + ' 23:59:59').getTime() / 1000
      } else {
        startTime = 0
        endTime = 0
      }
      this.$emit('handleTime', {
        startTime,
        endTime,
        val
      })
      console.log(val, startTime, endTime)
    }
  }
}
</script>

<style lang="scss">
</style>
